package org.wlgzs.office_exam_student.service.office;

import java.util.LinkedList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*@author song(mejeesong@qq.com)
*2018年1月25日
*解析Office的抽象层
*/
public interface OfficeResolver {
	static Logger logger = LoggerFactory.getLogger(OfficeResolver.class);
	ResolveResult resolve(String dir);
	String getKey();
	
	public static OfficeResolver generateResolver(org.wlgzs.office_exam_resolver.OfficeResolver resolver){
		return new AdapterResolver(resolver);
	}
	
	//适配解析项目中的解析类到本项目中的解析类
	class AdapterResolver implements OfficeResolver{
		private org.wlgzs.office_exam_resolver.OfficeResolver resolver = null;
		public AdapterResolver(org.wlgzs.office_exam_resolver.OfficeResolver resolver) {
			this.resolver = resolver;
		}

		@Override
		public ResolveResult resolve(String dir) {
			logger.debug(dir);
			org.wlgzs.office_exam_resolver.ResolveResult rr = this.resolver.resolve(dir);
			logger.debug(String.valueOf(rr));
			if(rr == null) {
				return new ResolveResult(0, 20, new LinkedList<>());
			}
			ResolveResult result = new ResolveResult(rr.score, rr.maxScore, rr.errors);
			return result;
		}

		@Override
		public String getKey() {
			return resolver.getKey();
		}
	}
}
